/**
 * Created with JetBrains WebStorm.
 * User: Eric
 * Date: 19/03/13
 * Time: 16:33
 * To change this template use File | Settings | File Templates.
 */
// We create a connection
var connector = require('./connector');
var connection = connector.connection();
// We need our model
var Building = require("../model/Building.js");



var persistBuilding= function(building){

    console.log("on est dans persists building");

    var post  = {type: building.type, storage: building.storage, price: building.price, tile: building.getTileForPersist()};

    if (building.id == null){
        connection.query('INSERT INTO building SET ?', post, function(err, rows, fields){

            if (err) throw err; // if there is an error we throw it
            callback(); // Callback basicaly it's the end of the controleur
        });
    }else{

        connection.query('update builidng SET ? where id = ?',[post,building.id], function(err, rows, fields){



            if (err) throw err; // if there is an error we throw it
            callback(); // Callback basicaly it's the end of the controleur
        });
    }


};





module.exports.persistBuilding = persistBuilding;
